package com.zhuss.vent.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.vent.vent.DeleteVentAppendBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;
import com.zhuss.vent.db.dao.ext.VentAppendDao;
import com.zhuss.vent.db.entity.VentAppend;

/**
 * 删除匿名吐槽Append processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("ventAppendDelete")
public class VentAppendDelete extends AbstractProcessor<Object, DeleteVentAppendBo> implements Processor<Object, DeleteVentAppendBo> {

    @Autowired
    private VentAppendDao ventAppendDao;
    
    /**
     * 校验
     */
	@Override
    public void check(DeleteVentAppendBo bo) throws WpsException {
    	
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeleteVentAppendBo param) throws WpsException {
    	Long ventAppendId = param.getVentAppendId();
    	
    	VentAppend record = new VentAppend();
    	record.setVentAppendId(ventAppendId);
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	ventAppendDao.delete(record);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeleteVentAppendBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.匿名吐槽.key());
    	record.setAction(LogActionEnum.匿名吐槽Append删除.key());
    	record.setTargetId(param.getVentAppendId());
    	record.setTargetName(param.getVentAppendId() + "");
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
